﻿using System;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;

namespace FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts
{
    [DataContract(Namespace = WebConstants.ServiceNamespace)]
    public class EmployeeCriteria : Employee
    {
        public EmployeeCriteria()
        {
            AddValidationFor(() => DateOfBirthFrom)
                .When(x =>
                          {
                              var xx = (EmployeeCriteria) x;
                              if (xx.DateOfBirthFrom.HasValue && xx.DateOfBirthTo.HasValue)
                                return  xx.DateOfBirthFrom.Value > xx.DateOfBirthTo.Value;
                              return false;

                          })
                .Show("Ngày sinh ko hợp lệ");

            AddValidationFor(() => DateOfBirthTo)
                .When(x =>
                {
                    var xx = (EmployeeCriteria)x;
                    if (xx.DateOfBirthFrom.HasValue && xx.DateOfBirthTo.HasValue)
                        return xx.DateOfBirthFrom.Value > xx.DateOfBirthTo.Value;
                    return false;

                })
                .Show("Ngày sinh ko hợp lệ");

            AddValidationFor(() => JoinedDateFrom)
                .When(x =>
                {
                    var xx = (EmployeeCriteria)x;
                    if (xx.JoinedDateFrom.HasValue && xx.JoinedDateTo.HasValue)
                        return xx.JoinedDateFrom.Value > xx.JoinedDateTo.Value;
                    return false;

                })
                .Show("Ngày ký hợp đồng ko hợp lệ");

            AddValidationFor(() => JoinedDateTo)
                .When(x =>
                {
                    var xx = (EmployeeCriteria)x;
                    if (xx.JoinedDateFrom.HasValue && xx.JoinedDateTo.HasValue)
                        return xx.JoinedDateFrom.Value > xx.JoinedDateTo.Value;
                    return false;

                })
                .Show("Ngày ký hợp đồng ko hợp lệ");

        }


        private DateTime? dateOfBirthFrom;
        [DataMember]
        public DateTime? DateOfBirthFrom
        {
            get { return dateOfBirthFrom; }
            set
            {
                if(!Equals(dateOfBirthFrom,value))
                {
                    dateOfBirthFrom = value;
                    RaisePropertyChanged(() => DateOfBirthFrom);
                }
            }
        }

        private DateTime? dateOfBirthTo;
        [DataMember]
        public DateTime? DateOfBirthTo
        {
            get { return dateOfBirthTo; }
            set
            {
                if (!Equals(dateOfBirthTo, value))
                {
                    dateOfBirthTo = value;
                    RaisePropertyChanged(() => DateOfBirthTo);
                }
            }
        }

       
        private ObservableCollection<int> roleIDCollection;
        [DataMember]
        public ObservableCollection<int> RoleIDCollection
        {
            get { return roleIDCollection; }
            set
            {
                if(!ReferenceEquals(roleIDCollection,value))
                {
                    roleIDCollection = value;
                    RaisePropertyChanged(() => RoleIDCollection);
                }
            }
        }

        private Role selectedRole;
        [DataMember]
        public Role SelectedRole
        {
            get { return selectedRole; }
            set
            {
                if (!Equals(selectedRole, value))
                {
                    selectedRole = value;
                    RaisePropertyChanged(() => SelectedRole);
                }
            }
        }

        private DateTime? joinedDateFrom;
        [DataMember]
        public DateTime? JoinedDateFrom
        {
            get { return joinedDateFrom; }
            set
            {
                if(!Equals(joinedDateFrom,value))
                {
                    joinedDateFrom = value;
                    RaisePropertyChanged(() => JoinedDateFrom);
                }
            }
        }

        private DateTime? joinedDateTo;
        [DataMember]
        public DateTime? JoinedDateTo
        {
            get { return joinedDateTo; }
            set
            {
                if (!Equals(joinedDateTo, value))
                {
                    joinedDateTo = value;
                    RaisePropertyChanged(() => JoinedDateTo);
                }
            }
        }
    }
}
